/*
 * Created on 2005-10-6
 *
 */
package com.yl.cap.analyst.config.listener;

import java.io.File;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import org.apache.log4j.Category;
import org.apache.log4j.Logger;
import org.springframework.context.ApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import com.yl.cap.analyst.config.ContextBean;

/**
 * @author ZhangQi
 *
 */
public class InitConfigListener implements ServletContextListener
{
    Category log = Logger.getLogger("reporte");
    
    /* (non-Javadoc)
     * @see javax.servlet.ServletContextListener#contextInitialized(javax.servlet.ServletContextEvent)
     */
    public void contextInitialized(ServletContextEvent event)
    {
        try
        {
            ApplicationContext context = WebApplicationContextUtils
                    .getWebApplicationContext(event.getServletContext());
            ContextBean.springContext = context;
            //get real path
            ContextBean.rootPath = event.getServletContext().getRealPath("/");
            ContextBean.licenseFile = new File(event.getServletContext().getRealPath("/conf/license/" + "license"));
        }
        catch (Exception e)
        {
            log.error("contextInitialized error",e);
        }
    }

    /* (non-Javadoc)
     * @see javax.servlet.ServletContextListener#contextDestroyed(javax.servlet.ServletContextEvent)
     */
    public void contextDestroyed(ServletContextEvent arg0)
    {
        // TODO Auto-generated method stub
        
    }

}
